/**
 * @author 0283000115
 * @date 2018年3月3日-下午2:32:37
 */
package com.zte.claa.inficombo.csa.app.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zte.claa.inficombo.csa.app.controller.ret.ApiResult;
import com.zte.claa.inficombo.csa.app.service.modbus.ModbusMainService;

import io.swagger.annotations.ApiOperation;

/**
 * @author hxl
 * 
 */

@Controller
@RequestMapping(value={"/modbusmaster"}, method = RequestMethod.GET)
public class ModbusMasterController extends BaseController {
	// logger
	private Logger logger = LoggerFactory.getLogger(ModbusMasterController.class);

	
	@Autowired 
	private ModbusMainService modbusMainService;
	
	
    @ApiOperation(value = "重启Modbus主站服务", notes = "")
    @RequestMapping(value={"/restart"}, method = RequestMethod.GET)
    @ResponseBody
	public ApiResult<?> reStart(HttpServletRequest request) throws Exception{
    	 ApiResult<String> ret = new ApiResult<String>();
    	try{
    		modbusMainService.destroy();
    		modbusMainService.init();
    		logger.error("Restart modbusmaster success");
            ret.setRemark("Restart modbusmaster success");
            ret.setResult(ApiResult.RET_SUCC); 
    	}catch(Exception e){
            ret.setRemark(e.getMessage());
            ret.setResult(ApiResult.RET_FAIL);              
            logger.error("Restart modbusmaster failed" + e.getMessage());
        }
        return ret;
	}
	

}
